

register_crad_rule('新手上路',{'敏捷','力量','智力','攻击'})
local list1 = {
    ['鸽王'] = {240,true},
    ['摸鱼仙人'] = {240,true},
    ['社死'] = {240,true},
    ['摆烂王'] = {240,false},
    ['舔狗'] = {240,false},
    ['内卷风暴'] = {240,false},
    ['破防の刃'] = {240,false},
    ['雪糕刺客'] = {240,false},
    ['哈基米'] = {240,false},
    ['绝绝子'] = {240,false},
    ['PUA大师'] = {240,false},
    ['福报'] = {240,false},
    ['作者的原味内裤'] = {240,false},
    ['魔影游戏'] = {240,false},

}


local list2 = {
    ['白胡子老爷爷'] ={200,true},
    ['天选打工人'] ={200,true},
    ['真香定律'] ={200,true},
    ['键盘侠'] ={300,true},
    ['电子榨菜'] ={300,true},
}

ac.game:event '英雄-抽卡完毕'(function(_,hero,temp)
    local player = hero.owner
    local Lock = player:get_data('无法获得卡') or {}
    local list = list1[temp.name]
    if list then
        temp.timer_count = ac.wait(list[1]*1000,function()
            hide_card(temp)
            if list[21] then
                Lock[temp.name] = nil
            end
        end)
        temp:gc(temp.timer_count)
    end


    local list = list2[temp.name]
    if list then
        local count = 0
        temp.show_num = list[1]
        temp:gc(hero:event '单位-击杀'(function()
            temp.show_num  = temp.show_num - 1
            if temp.show_num<=0 then
                hide_card(temp)
                if list[2] then
                    Lock[temp.name] = nil
                end
            end
        end))
    end
end)



local mt = ac.skill['*新手上路']
function mt:on_add()
    local hero = self.owner
    hero:set_data('新手上路',true)
    self:gc(hero:add('每秒经验',self.data1))
    self:gc(hero:add('每秒金币',self.data2))
    self:gc(hero:add('每秒木材',self.data3))
    local skill = self.owner_skill or self
    
    skill.timer_count = ac.wait(400*1000,function()
        hide_card(skill)
    end)
    skill:gc(skill.timer_count)
end

local mt = ac.skill['彻底摆烂']
function mt:on_add()
    local hero = self.owner
    local last = hero:get_point()
    local time = 0
    self:gc(ac.loop(100,function()
        local point = hero:get_point()
        if point*last==0 then
            if hero['摆烂']==nil then
                time = time + 0.1
                if time>=3 then
                    time = 0
                    hero['摆烂'] = hero:add_buff '彻底摆烂'{
                        art = self.art,
                        pulse = 1,
                        tip = self:get_tip(),
                        keep = true,
                        not_show_pulse = true,
                        on_pulse = function(buff)
                            hero:add('生命',hero:get('生命上限')*self.data1/100)
                        end
                    }
                end
            end
        else
            if hero['摆烂'] then
                hero['摆烂']:remove()
                hero['摆烂'] = nil
            end
        end
        last = point
    end))

    self:gc(function()
        if hero['摆烂'] then
            hero['摆烂']:remove()
            hero['摆烂'] = nil
        end
    end)
end



local mt = ac.skill['开舔']
function mt:on_add()
    local hero = self.owner
    self:gc(hero:add_buff(self.name){
        art = self.art,
        tip = self:get_tip(),
        keep = true,
        on_add = function(buff)
            local attack_target = nil
            local count = 0
            local num = self.data1
            buff.stack = count
            buff:gc(hero:event '单位-攻击命中'(function(_,_,target,data)
                if attack_target==target then
                    count = math.min(count + 1,self.data2)
                    data:mul(num*count)
                else
                    count = 0
                end
                attack_target = target
                buff.stack = count
            end))
        end
    })
end


local mt = ac.skill['破防']
mt.temp = '攻击触发'
mt.odds = 50
function mt:on_init()
    self.odds = self.data3
end
function mt:on_run(hero,target)
    local damage = hero:get('攻击') * self.data2 / 100
    hero:create_damage(target,damage,self)
    target:add_buff '破防效果'{
        data1 = self.data1
    }
end

local buff = ac.buff['破防效果']
buff.data1 = 0
function buff:on_add()
    local hero = self.owner
    self:gc(hero:add_effect([[6c10a3376824c094388be227c9b85bf3.mdl]],'overhead'))
    self:gc(hero:add('护甲加成',-self.data1))
end


local mt = ac.skill['真刺客']
function mt:on_add()
    local hero = self.owner
    self:gc(hero:event '单位-攻击命中'(function(_,_,target,data)
        if not hero:find_buff '雪糕刺客' then
            local damage = hero:get(self['属性1']) * self.data1/100
            hero:add_buff '雪糕刺客'{}
            hero:create_damage(target,damage,self)
        end
    end))
end


local mt = ac.skill['哈气了']
function mt:on_add()
    local hero = self.owner
    self:gc(hero:event '单位-攻击命中'(function()
        hero:add_buff(self.name){
            art = self.art,
            tip = [[攻速的提升中]],
            keep = true,
            time = self.data3,
            stack = 0,
            on_add = function(buff)
                buff.stack = buff.stack + 1
                buff:gc(hero:add('攻击速度',self.data1))
            end,
            on_cover = function(buff)
                if buff.stack<self.data2 then
                    buff:on_add()
                end
                buff:set_remaining(buff.time)
            end
        }
        
    end))
end

local mt = ac.skill['跺jojo']
function mt:on_add()
    local hero = self.owner
    self:gc(hero:event '单位-造成伤害前'(function(_,_,target,data)
        if target:is_type('精英') then
            data:mul(self.data1)
        end
    end))
end


local mt = ac.skill['CPU']
function mt:on_add()
    local hero = self.owner
    self:gc(hero:event '单位-攻击命中'(function(_,_,target,data)
        target:add_buff 'PUA大师'{time = self.data2,effect_data = {
            ['origin'] = [[Abilities\Spells\Other\HowlOfTerror\HowlTarget.mdl]]
        }}
    end))
    self:gc(hero:event '单位-受到伤害'(function(_,_,target,data)
        if target:find_buff 'PUA大师' then
            data:div(self.data1)
        end
    end))
end


local mt = ac.skill['薪水']
function mt:on_add()
    local hero = self.owner
    self:gc(hero:add('每秒金币',self.data1))
end


local mt = ac.skill['灵感迸发']
function mt:on_add()
    local hero = self.owner
    self:gc(hero:add_buff(self.name){
        art = self.art,
        tip = self:get_tip(),
        keep = true,
        on_add = function(buff)
            local count = 0
            self:gc(ac.loop(1000,function()
                if hero:is_fight_active() then
                    if count<self.data2 then
                        count = count + 1
                        hero:add('全属性加成',self.data1)
                    end
                else
                    hero:add('全属性加成', -count*self.data1)
                    count = 0
                end
                buff.stack = count
            end))
            self:gc(function()
                hero:add('全属性加成', -count)
            end)
        end
    })

end

local mt = ac.skill['上头']
function mt:on_add()
    local hero = self.owner
    self:gc(hero:event '单位-获得经验'(function(_,_,xp)
        if math.random(100)<=self.data1 then
            hero:add_exp(xp)
        end
    end))
end

local mt = ac.skill['进击的作者']
function mt:on_add()
    local hero = self.owner
    self:gc(hero:add_buff(self.name){
        art = self.art,
        tip = self:get_tip(),
        keep = true,
        pulse = self.data1,
        on_pulse = function(buff)
            hero:add_level(self.data2)
        end
    })

end


local mt = ac.skill['规则制定者']
function mt:on_add()
    local hero = self.owner
    self:gc(ac.loop(self.data1*1000,function()
        local name = ('游戏规则%s'):format(math.random(5))
        ac.each_player(function()
            local hero = self.owner
            if hero then
                hero:add_buff(name){time = self.data1,art = self.art}
            end
        end)
    end))
end


local buff = ac.buff['游戏规则1']
buff.tip = [[物理伤害翻倍]]
function buff:on_add()
    self:gc(self.owner:add('物理伤害%',100))
end

local buff = ac.buff['游戏规则2']
buff.tip = [[攻击速度+100%]]
function buff:on_add()
    self:gc(self.owner:add('攻击速度',100))
end

local buff = ac.buff['游戏规则3']
buff.tip = [[金币翻倍]]
buff.time = 1
function buff:on_add()
    self.owner.owner:add('金币',self.owner.owner:get('金币'))
end

local buff = ac.buff['游戏规则4']
buff.tip = [[技能伤害翻倍]]
function buff:on_add()
    self:gc(self.owner:add('技能伤害%',100))
end


local buff = ac.buff['游戏规则5']
buff.tip = [[禁止治疗]]
function buff:on_add()
    self.owner:add_restriction '禁疗'
    self:gc(function()
        self.owner:remove_restriction '禁疗'
    end)
end


local mt = ac.skill['龙皇冲击破']
mt.temp = '攻击触发'
mt.model1 = [[Abilities\Weapons\PhoenixMissile\Phoenix_Missile.mdl]]
function mt:on_run(hero,target)
    local point1 = hero:get_point()
    local point2 = target:get_point()
    local angle = point1 / point2
    local point3 = point1 - {angle,-600}
    local point4 = point3 - {angle,600}
    local unit = ac.player[16]:create_unit('远古龙皇',point3,angle)
    local sd = ac.lightning({
        id = 'SRAY',
        from = unit,
        to = point4,
        ozf = 300,
    })
    unit:add_restriction '蝗虫'
    local lock = {}
    local damage = hero:get('攻击') * self.data1/100 + hero:get('力量') * self.data2/100
    ac.mover('line'){
        start = point3,
        angle = angle,
        mover = unit,
        speed = 1200,
        distance = 2400,
        need_remove_mover = true,
        on_move = function(p,b)
            local point = unit:get_point() - {angle,600}
            point.z = point3:get_height()
            sd.to = point
            point:add_effect(self.model1):remove()
            hero:aoe_damage(point,300,damage,self,lock)
        end,
        on_remove = function()
            sd:remove()
        end
    }
    ac.wait(10,function()
        local skill = self.owner_skill or self
        skill.timer_count = self.cast_cd_timer
    end)
end